package com.ideal.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ideal.dto.Page;
import com.ideal.dto.ResultDto;
import com.ideal.model.Config;
import com.ideal.service.IConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 配置Controller
 *
 * @author songfz
 * @date 2022-07-13
 */
@Controller
@RequestMapping("/ideal/config")
public class ConfigController
{
    @Autowired
    private IConfigService configService;

    /**
     * 查询配置列表
     */
    @RequestMapping(value = "/list",method = RequestMethod.POST)
    @ResponseBody
    public Page list(@RequestBody Config config)
    {
        List<Config> list = configService.selectConfigList(config);
        return new Page();
    }


    /**
     * 获取配置详细信息
     */
    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    @ResponseBody
    public ResultDto getInfo(@PathVariable("id") Long id)
    {
        Config config = configService.selectConfigById(id);
        return ResultDto.success(config);
    }

    /**
     * 新增配置
     */
    @RequestMapping(value = "save",method = RequestMethod.POST)
    @ResponseBody
    public ResultDto add(@RequestBody Config config)
    {
        return ResultDto.success(configService.insertConfig(config));
    }

    /**
     * 修改配置
     */
    @RequestMapping(value = "edit",method = RequestMethod.PUT)
    @ResponseBody
    public ResultDto edit(@RequestBody Config config)
    {
        return ResultDto.success(configService.updateConfig(config));
    }


    public static void main(String[] args) throws JsonProcessingException {
        HashMap<String, String[][]> map = new HashMap<>();

        String[][] context;

        context = new String[][]{{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"},
                {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
                , {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"},
                {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}};
        map.put("sheet1",context);
        String s = new ObjectMapper().writeValueAsString(map);
        System.out.println(s);
        System.out.println(new ObjectMapper().readValue(s, Map.class));

    }
}
